home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / manageme / tcpdump-.001 / tcpdump-~ / tcpdump-3.0.2-linux / tcpdump-3.0.2 / print-ipx.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-21  |  5.1 KB  |  213 lines

  1. /*
  2.  * Copyright (c) 1994
  3.  *    The Regents of the University of California.  All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that: (1) source code distributions
  7.  * retain the above copyright notice and this paragraph in its entirety, (2)
  8.  * distributions including binary code include the above copyright notice and
  9.  * this paragraph in its entirety in the documentation or other materials
  10.  * provided with the distribution, and (3) all advertising materials mentioning
  11.  * features or use of this software display the following acknowledgement:
  12.  * ``This product includes software developed by the University of California,
  13.  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
  14.  * the University nor the names of its contributors may be used to endorse
  15.  * or promote products derived from this software without specific prior
  16.  * written permission.
  17.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  18.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  19.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  20.  */
  21.  
  22. /*
  23.  * Format and print Novell IPX packets.
  24.  * Contributed by Brad Parker (brad@fcr.com).
  25.  */
  26. #ifndef lint
  27. static  char rcsid[] =
  28.     "@(#)$Header: print-ipx.c,v 1.6 94/06/20 19:44:38 leres Exp $";
  29. #endif
  30.  
  31. #include <sys/param.h>
  32. #include <sys/types.h>
  33. #include <sys/socket.h>
  34.  
  35. #include <netinet/in.h>
  36. #include <netinet/in_systm.h>
  37. #include <netinet/ip.h>
  38. #include <netinet/ip_var.h>
  39. #include <netinet/udp.h>
  40. #include <netinet/udp_var.h>
  41. #include <netinet/tcp.h>
  42. #include <netinet/tcpip.h>
  43.  
  44. #ifdef __STDC__
  45. #include <stdlib.h>
  46. #endif
  47. #include <stdio.h>
  48. #include <string.h>
  49.  
  50. #include "interface.h"
  51. #include "addrtoname.h"
  52. #include "ipx.h"
  53. #include "extract.h"
  54.  
  55.  
  56. static const char *ipxaddr_string(u_int32 net, const u_char *node);
  57. void ipx_decode(const struct ipxHdr *ipx, const u_char *datap, int length);
  58. void ipx_sap_print(const u_short *ipx, int length);
  59. void ipx_rip_print(const u_short *ipx, int length);
  60.  
  61. /*
  62.  * Print IPX datagram packets.
  63.  */
  64. void
  65. ipx_print(const u_char *p, int length)
  66. {
  67.     const struct ipxHdr *ipx = (const struct ipxHdr *)p;
  68.  
  69.     if (length < ipxSize) {
  70.         (void)printf(" truncated-ipx %d", length);
  71.         return;
  72.     }
  73.     (void)printf("%s.%x > ",
  74.              ipxaddr_string(EXTRACT_LONG(ipx->srcNet), ipx->srcNode),
  75.              EXTRACT_SHORT(&ipx->srcSkt));
  76.  
  77.     (void)printf("%s.%x:",
  78.              ipxaddr_string(EXTRACT_LONG(ipx->dstNet), ipx->dstNode),
  79.              EXTRACT_SHORT(&ipx->dstSkt));
  80.  
  81.     if ((u_char *)(ipx + 1) > snapend) {
  82.         printf(" [|ipx]");
  83.         return;
  84.     }
  85.  
  86.     /* take length from ipx header */
  87.     length = EXTRACT_SHORT(&ipx->length);
  88.  
  89.     ipx_decode(ipx, (u_char *)ipx + ipxSize, length - ipxSize);
  90. }
  91.  
  92. static const char *
  93. ipxaddr_string(u_int32 net, const u_char *node)
  94. {
  95.     static char line[256];
  96.  
  97.     sprintf(line, "%lu.%02x:%02x:%02x:%02x:%02x:%02x",
  98.         net, node[0], node[1], node[2], node[3], node[4], node[5]);
  99.  
  100.     return line;
  101. }
  102.  
  103. void
  104. ipx_decode(const struct ipxHdr *ipx, const u_char *datap, int length)
  105. {
  106.     switch (EXTRACT_SHORT(&ipx->dstSkt)) {
  107.       case IPX_SKT_NCP:
  108.     (void)printf(" ipx-ncp %d", length);
  109.     break;
  110.       case IPX_SKT_SAP:
  111.     ipx_sap_print((u_short *)datap, length);
  112.     break;
  113.       case IPX_SKT_RIP:
  114.     ipx_rip_print((u_short *)datap, length);
  115.     break;
  116.       case IPX_SKT_NETBIOS:
  117.     (void)printf(" ipx-netbios %d", length);
  118.     break;
  119.       case IPX_SKT_DIAGNOSTICS:
  120.     (void)printf(" ipx-diags %d", length);
  121.     break;
  122.       default:
  123.     (void)printf(" ipx-#%x %d", ipx->dstSkt, length);
  124.     break;
  125.     }
  126. }
  127.  
  128. void
  129. ipx_sap_print(const u_short *ipx, int length)
  130. {
  131.     int command, i;
  132.  
  133.     if (length < 2) {
  134.     (void)printf(" truncated-sap %d", length);
  135.     return;
  136.     }
  137.  
  138.     command = EXTRACT_SHORT(ipx);
  139.     ipx++;
  140.     length -= 2;
  141.  
  142.     switch (command) {
  143.       case 1:
  144.       case 3:
  145.     if (command == 1)
  146.         (void)printf("ipx-sap-req");
  147.     else
  148.         (void)printf("ipx-sap-nearest-req");
  149.  
  150.     if (length > 0)
  151.         (void)printf(" %x '%.48s'", EXTRACT_SHORT(&ipx[0]),
  152.              (char*)&ipx[1]);
  153.     break;
  154.  
  155.       case 2:
  156.       case 4:
  157.     if (command == 2)
  158.         (void)printf("ipx-sap-resp");
  159.     else
  160.         (void)printf("ipx-sap-nearest-resp");
  161.  
  162.     for (i = 0; i < 8 && length > 0; i++) {
  163.         (void)printf(" %x '%.48s' addr %s",
  164.              EXTRACT_SHORT(&ipx[0]), (char *)&ipx[1],
  165.              ipxaddr_string(EXTRACT_LONG(&ipx[25]),
  166.                     (u_char *)&ipx[27]));
  167.         ipx += 32;
  168.         length -= 64;
  169.     }
  170.     break;
  171.       default:
  172.         (void)printf("ipx-sap-?%x", command);
  173.     break;
  174.     }
  175. }
  176.  
  177. void
  178. ipx_rip_print(const u_short *ipx, int length)
  179. {
  180.     int command, i;
  181.  
  182.     if (length < 2) {
  183.     (void)printf(" truncated-ipx %d", length);
  184.     return;
  185.     }
  186.  
  187.     command = EXTRACT_SHORT(ipx);
  188.     ipx++;
  189.     length -= 2;
  190.  
  191.     switch (command) {
  192.       case 1:
  193.     (void)printf("ipx-rip-req");
  194.     if (length > 0)
  195.         (void)printf(" %lu/%d.%d", EXTRACT_LONG(&ipx[0]),
  196.              EXTRACT_SHORT(&ipx[2]), EXTRACT_SHORT(&ipx[3]));
  197.     break;
  198.       case 2:
  199.     (void)printf("ipx-rip-resp");
  200.     for (i = 0; i < 50 && length > 0; i++) {
  201.         (void)printf(" %lu/%d.%d", EXTRACT_LONG(&ipx[0]),
  202.              EXTRACT_SHORT(&ipx[2]), EXTRACT_SHORT(&ipx[3]));
  203.  
  204.         ipx += 4;
  205.         length -= 8;
  206.     }
  207.     break;
  208.       default:
  209.         (void)printf("ipx-rip-?%x", command);
  210.     }
  211. }
  212.  
  213.